#
# Licensed to Selene developers ('Selene') under one or more
# contributor license agreements.  See the NOTICE file distributed with
# this work for additional information regarding copyright ownership.
# Selene licenses this file to You under the Apache License, Version 2.0
# (the "License"); you may not use this file except in compliance with
# the License.  You may obtain a copy of the License at
#
#     http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
#

Import('venv')

sources = Split("""
  utils.c
  test_alert_io.c
  test_all.c
  test_brigrade.c
  test_buckets.c
  test_certs.c
  test_crypto_digest.c
  test_crypto_prf.c
  test_events.c
  test_handshake_io.c
  test_init.c
  test_logging.c
  test_loopback.c
  test_tls_io.c
  test_tok.c
""")


lenv = venv.Clone()
lenv.AppendUnique(CPPPATH=['#/extern/cmockery/src/google'])
lenv.AppendUnique(CPPPATH=['#/include/private'])
#lenv.AppendUnique(CPPDEFINES=['UNIT_TESTING=1'])
lenv.AppendUnique(CPPDEFINES=['LargestIntegralTypePrintfFormat=\\"%llu\\"'])
cenv = lenv.Clone()
cenv['CCFLAGS'] = filter(lambda x: x not in ["-Wall", "-pedantic", "-std=gnu89"], cenv['CCFLAGS'])
cenv.Command("cmockery.c", cenv.File('#/extern/cmockery/src/cmockery.c'), Copy("$TARGET", "$SOURCE"))
cmock = cenv.StaticLibrary('libcmockery', source=cenv.File('cmockery.c'))

tenv = lenv.Clone()
tenv.AppendUnique(CPPATH=['#/tests'])
tenv.AppendUnique(LIBS=cmock)
tenv.AppendUnique(LIBS=tenv['libselene'])
tenv.AppendUnique(CCFLAGS=['-Wno-long-long'])
tenv.AppendUnique(CPPDEFINES=['SLN_TEST_ALL=1'])
tests = []

tests.append(tenv.Program('test_all', source=sources))

Return('tests')
